﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DungeonMaker
{
    class GUI
    {
        public GUI() { }

        public char GetCharcode(byte b) 
        {
            return Encoding.GetEncoding(437).GetChars(new byte[] { b })[0];
        }

        public Position centerText(string text, int height = 0) 
        {
            int w = 0;
            
            try
            {
                w = text.Length/2;
                if (w > (Console.WindowWidth / 2))
                {
                    w = Console.WindowWidth / 2;
                }
            }
            catch (NullReferenceException)
            {
                w = 0;
                //throw;
            }
            

            return new Position((Console.WindowWidth / 2 -w), height);
        }

        public void WriteTextAt(string text, Position pos, ConsoleColor c = ConsoleColor.White) 
        {
            Console.ForegroundColor = c;
                Console.SetCursorPosition(pos.X, pos.Y);
                Console.Write(text);
            Console.ResetColor();
            Console.SetCursorPosition(0, 0);
        }
        public void WriteCharAt(char ch, Position pos, ConsoleColor c = ConsoleColor.White) 
        {
            Console.ForegroundColor = c;
            Console.SetCursorPosition(pos.X, pos.Y);
            Console.Write(ch);
            Console.ResetColor();
            Console.SetCursorPosition(0, 0);
        }
    }
}
